package com.cuit.lotery.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cuit.lotery.entity.Users;
import com.cuit.lotery.mapper.UsersMapper;
import com.cuit.lotery.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UsersServiceImpl implements UsersService {
    @Autowired
    UsersMapper mapper;
    @Override
    public List<Users> getAlll() {
        return mapper.selectList(null);
    }

    @Override
    public boolean userLogin(Users user) {
        if(user == null){
            return false;
        } else {
            Users usr = getByUserName(user.getUsername());
            if(usr == null){
                return false;
            } else {
                return usr.getPassword().equals(user.getPassword());
            }
        }
    }

    @Override
    public Users getByUserName(String username) {
        return mapper.selectOne(new QueryWrapper<Users>()
                .eq("username", username));
    }
}
